import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
// import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { useI18n } from '/@/hooks/web/useI18n';
import { log } from 'console';
const { t: antenna } = useI18n('device.antenna.fields');
const { t: common } = useI18n('common');
const fields = {
  deviceName: antenna('device_name'),
  serialNumber: antenna('serial_number'),
  deviceModel: antenna('device_model'),
  position: antenna('position'),
  useState: antenna('use_status'),
  onlineStatus: antenna('online_state'),
  functionDefine: antenna('function_define'),
  notes: antenna('notes'),
};
//列表数据
export const columns: BasicColumn[] = [
  {
    title: fields.deviceName,
    align: 'center',
    dataIndex: 'deviceName',
  },
  {
    title: fields.serialNumber,
    align: 'center',
    dataIndex: 'serialNumber',
  },
  {
    title: fields.deviceModel,
    align: 'center',
    dataIndex: 'deviceModel',
  },

  {
    title: fields.position,
    align: 'center',
    dataIndex: 'position_dictText',
    customRender({ text }) {
      console.log('position', text);
    },
  },
  {
    title: fields.useState,
    align: 'center',
    dataIndex: 'useState',
    customRender({ text }) {
      return render.renderDict(text, 'deviceUseStates');
    },
  },
  {
    title: fields.onlineStatus,
    align: 'center',
    dataIndex: 'onlineStatus',
    customRender({ text }) {
      return render.renderDict(text, 'deviceOnlineStates');
    },
  },
  {
    title: fields.functionDefine,
    align: 'center',
    dataIndex: 'functionalDefinition',
    customRender({ text }) {
      return render.renderDict(text, 'functionalDefinition');
    },
  },
  {
    title: fields.notes,
    align: 'center',
    dataIndex: 'notes',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: fields.deviceName,
    field: 'deviceName',
    component: 'JInput',
    colProps: { span: 6 },
    componentProps: { type: 'like' },
  },
  {
    label: fields.serialNumber,
    field: 'serialNumber',
    component: 'JInput',
    colProps: { span: 6 },
    componentProps: { type: 'like' },
  },
  {
    label: fields.onlineStatus,
    field: 'onlineStatus',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'deviceOnlineStates',
    },
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: fields.deviceName,
    field: 'deviceName',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + fields.deviceName }];
    },
    colProps: { span: 12 },
  },
  {
    label: fields.serialNumber,
    field: 'serialNumber',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + fields.serialNumber }];
    },
    colProps: { span: 12 },
  },

  {
    label: fields.useState,
    field: 'useState',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'deviceUseStates',
    },
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + fields.useState }];
    },
    colProps: { span: 12 },
  },
  {
    label: fields.position,
    field: 'position',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'asset_position,position_name,id',
      pidField: 'pid',
      pidValue: '0',
      hasChildField: 'has_child',
    },
    colProps: { span: 12 },
  },
  {
    label: fields.deviceModel,
    field: 'deviceModel',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    label: fields.functionDefine,
    field: 'functionalDefinition',
    component: 'JDictSelectTag',
    componentProps: {
      //字典code配置，比如通过性别字典编码：sex，也可以使用demo,name,id 表名,名称,值的方式
      dictCode: 'functionalDefinition',
      //支持radio(单选按钮)、radioButton(单选按钮 btn风格)、select(下拉框)
      type: 'radioButton',
    },
    colProps: { span: 12 },
  },
  {
    label: fields.notes,
    field: 'notes',
    component: 'JEditor',
    colProps: { span: 12 },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
